<template>
  <a-drawer
    :maskClosable="false"
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
    <erp-finance-reimbursement-bill-form ref="realForm" @ok="submitCallback" @unButtonDisable="unButtonDisable" :disabled="disableSubmit" normal></erp-finance-reimbursement-bill-form>
    <div class="drawer-footer">
      <CommonDrawerFooterButton
        startProcess="erpFinanceReimbursementBill: startProcess"
        :disableSubmit="disableSubmit"
        :buttonDisable="buttonDisable"
        @handleCancel="handleCancel"
        @handleOk="handleOk"
        @beginProcess="beginProcess"
      ></CommonDrawerFooterButton>
    </div>
  </a-drawer>
</template>

<script>

  import ErpFinanceReimbursementBillForm from './ErpFinanceReimbursementBillForm'
  import { getAction } from '@/api/manage'
  import CommonDrawerFooterButton from '@/views/components/CommonDrawerFooterButton.vue';
  import { ModalClickMixin } from '@/mixins/ModalClickMixin'
  export default {
    name: 'ErpFinanceReimbursementBillModal',
    components: {
      ErpFinanceReimbursementBillForm,
      CommonDrawerFooterButton
    },
    mixins: [ModalClickMixin],
    data () {
      return {
        url: {
          querySalaryFeeById: '/api/erp/finance/reimbursement/erpFinanceReimbursementSalaryFeeInfo/queryByBillId',
          querySalaryFeeListById: '/api/erp/finance/reimbursement/erpFinanceReimbursementSalaryFeeInfo/querySalaryFeeListById',
          queryPurchaseyFeeById: '/api/erp/finance/reimbursement/erpFinanceReimbursementPurchaseyFeeInfo/queryByBillId',
          queryDailyFeeById: '/api/erp/finance/reimbursement/erpFinanceReimbursementDailyFeeInfo/list'
        }
      }
    },
    methods: {
      add () {
        this.buttonDisable = false
        this.visible = true
        this.$nextTick(() => {
          this.$refs.realForm.add();
        })
      },
      async edit (record, flag) {
        this.buttonDisable = false
        this.visible = true
        if (flag) {
          if (record.feeCategory == '0') {
            let url = this.url.querySalaryFeeListById
            record.purchaseyFeeInfo = { 'bigCategory': null, 'smallCategory': null, 'taxation': 0 };
            record.dailyFeeInfoList = [];
            record.salaryFeeInfoList = await this.getChildTableData(url, record);
          } else if (record.feeCategory == '1') {
            let url = this.url.queryPurchaseyFeeById
            record.purchaseyFeeInfo = await this.getChildTableData(url, record);
            record.salaryFeeInfo = { 'bigCategory': null, 'smallCategory': null, 'taxation': 0 };
            record.dailyFeeInfoList = [];
          } else if (record.feeCategory == '2') {
            let url = this.url.queryDailyFeeById
            record.purchaseyFeeInfo = { 'bigCategory': null, 'smallCategory': null, 'taxation': 0 };
            record.salaryFeeInfo = { 'bigCategory': null, 'smallCategory': null, 'taxation': 0 };
            record.dailyFeeInfoList = await this.getChildTableData(url, record);
          }
        }
        this.$nextTick(() => {
          this.$refs.realForm.edit(record);
        });
      },
      // 获取子表数据
      getChildTableData(url, record) {
        let param = { billId: record.id }
        return new Promise((resolve) => {
          getAction(url, param).then((res) => {
            if (res.success) {
              let data = res.result;
              if (data.records != undefined) {
                resolve(data.records);
              }
              resolve(data);
            } else {
              resolve([])
            }
          })
        })
      }
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
  .drawer-footer{
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
    z-index: 100;
  }
</style>
